FrameLib  0.7
DSP processing with frames of arbitrary timing and length
FrameLib_Global.h
Go to the documentation of this file.
1 
2 #ifndef FRAMELIB_GLOBAL_H
3 #define FRAMELIB_GLOBAL_H
4 
5 #include "FrameLib_Memory.h"
7 #include "FrameLib_Threading.h"
8 #include <vector>
9 
10 // The Global Object
11 
13 {
14 
15  friend class FrameLib_Context;
16 
17 private:
18 
19  template <class T> class PointerSet
20  {
21  // A simple countable pointer with a reference address
22 
23  struct CountablePointer
24  {
25  CountablePointer(T* object, void *reference) : mObject(object), mReference(reference), mCount(1) {}
26 
27  T *mObject;
28  void *mReference;
29  long mCount;
30  };
31 
32  public:
33 
34  // Add, find or release an object by reference address
35 
36  void add(T *object, void *reference);
37  T *find(void *reference);
38  void release(void *reference);
39 
40  private:
41 
42  // Type definition for concision and internal pointers
43 
44  typedef std::vector<CountablePointer> VectorType;
45 
46  VectorType mPointers;
47  };
48 
49  // Constructor / Destructor
50 
51  FrameLib_Global() : mCount(0) {}
52  ~FrameLib_Global() {};
53 
54  // Deleted
55 
57  FrameLib_Global& operator=(const FrameLib_Global&);
58 
59 public:
60 
61  // Retrieve and release the global object
62 
63  static FrameLib_Global *get(FrameLib_Global **global);
64  static void release(FrameLib_Global **global);
65 
66 private:
67 
68  // Methods to retrieve common objects
69 
70  FrameLib_LocalAllocator *getAllocator(void *reference);
71  FrameLib_ProcessingQueue *getProcessingQueue(void *reference);
72 
73  // Methods to release common objects
74 
75  void releaseAllocator(void *reference);
76  void releaseProcessingQueue(void *reference);
77 
78  // Reference Counting / Auto-deletion
79 
80  void increment();
81  FrameLib_Global *decrement();
82 
83  // Common Objects
84 
85  FrameLib_GlobalAllocator mAllocator;
86 
87  PointerSet<FrameLib_LocalAllocator> mLocalAllocators;
88  PointerSet<FrameLib_ProcessingQueue> mProcessingQueues;
89 
90  SpinLock mLock;
91  long mCount;
92 };
93 
94 #endif
Definition: FrameLib_Global.h:12
Definition: FrameLib_Threading.h:130
Definition: FrameLib_Context.h:10
static void release(FrameLib_Global **global)
Definition: FrameLib_Global.cpp:62
Definition: FrameLib_ProcessingQueue.h:12
Definition: FrameLib_Memory.h:14
Definition: FrameLib_Memory.h:197